#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
@author:atuo.cn
'''

from tkinter import *
from tkinter.ttk import *
from tkinter.scrolledtext import ScrolledText
from tkinter.simpledialog import Dialog

from dialogs.dialoghelper import DialogHelper

class SectionDialogLayout(Dialog, DialogHelper):
    def __init__(self, master, wmtitle):
        Dialog.__init__(self, master, wmtitle)
        
    #override method of Dialog to create main frame
    def body(self, master):
        #title
        frame=Frame(master)
        frame.pack(fill=X,expand=1)
        self.label1 = Label(frame, text="标题")
        self.label1.pack(anchor=W)
        self.title=StringVar()
        self.entryTitle=Entry(frame, textvariable=self.title,width=100)
        self.entryTitle.pack(fill=X,expand=1)
        #raw title
        frame=Frame(master)
        frame.pack(fill=X,expand=1)
        self.label2 = Label(frame, text="标题原文")
        self.label2.pack(anchor=W)
        self.rawtitle=StringVar()
        self.entryRawTitle = Entry(frame, textvariable=self.rawtitle)
        self.entryRawTitle.state(["readonly"])
        self.entryRawTitle.pack(fill=X,expand=1)
        
        #content
        frame=Frame(master)
        frame.pack(fill=BOTH,expand=1)
        self.label3=Label(frame, text="章节内容")
        self.label3.pack(anchor=W)
        self.textContent=ScrolledText(frame,width=100,undo=True, spacing3=10)
        self.textContent.pack(fill=BOTH, expand=1)
        
        self._bindEvents()
        self.onLoad()
        self.update_idletasks()
    
    #override the method of Dialog to allow press Enter & Escape     
    def buttonbox(self):
        box = Frame(self)

        w = Button(box, text="OK", width=10, command=self.ok, default=ACTIVE)
        w.pack(side=LEFT, padx=5, pady=5)
        w = Button(box, text="Cancel", width=10, command=self.cancel)
        w.pack(side=LEFT, padx=5, pady=5)

        box.pack()        
                
    def _bindEvents(self):
        pass
        
    def onLoad(self):
        pass

            
if __name__=="__main__":
    root=Tk()
    dialog=SectionDialogLayout(root,"Test")
    root.mainloop()